var express = require('express');
const { get } = require('mongoose');
var router = express.Router();
const { getCustomers, addCustomer, updateCustomerById, delCustomerById, getCustomerById } = require('../service/customersService.js')

//获取所有客户
router.get('/getCustomers', async function (req, res, next) {
  const result = await getCustomers();
  // console.log(11111111,result);
  res.send(result);
});

//通过id获取客户
router.get('/getCustomerById', async function (req, res, next) {
  // console.log(11111111,req.query._id);
  const result = await getCustomerById(req.query._id);
  res.send(result);
})

//新增客户
router.post('/addCustomer', async function (req, res, next) {
  const result = await addCustomer(req.body);
  console.log(111111, req.body);
  res.send(result);
})

//修改客户
router.post('/updateCustomerById', async function (req, res, next) {
  const result = await updateCustomerById(req.body);
  res.send();
})

//删除客户
router.get('/delCustomerById', async function (req, res, next) {
  console.log(1111,req.query);
  const result = await delCustomerById(req.query._id);
  res.send();
})

module.exports = router;